<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        var n = parseInt(prompt("请输入一个正整数"));
        function perfect(a){
            //累加器
            var sum = 0;
            //循环累加约数
            for(var i = 1; i < a; i++){
                if(a % i === 0){
                    sum+=i;
                }
            }
            //循环结束后，sum中存了a的约束和
            return sum;
        }
        function isNum(a){
            if(perfect(a) === a){
                return true;
            }
            else{
                return false;
            }
        }
        if(isNum(n)){
            alert(n + "是一个完美数");
        }else{
            alert(n + "不是一个完美数");
        }

    </script>
</head>
<body>
    
</body>
</html>